//
//  DiscoveryHeaderView.m
//  PigMarket
//
//  Created by mac on 2019/6/28.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "DiscoveryHeaderView.h"

@interface DiscoveryView : UIImageView

@property (nonatomic, strong) UILabel *titelLab;

@property (nonatomic, strong) UILabel *detailLab;

@end


@implementation DiscoveryView

- (instancetype)init{
    
    self = [super init];
    if (self) {
        
        [self addSubview:self.titelLab];
        [self addSubview:self.detailLab];
        [self setupLayout];
        
    }
    return self;
}

- (void)setupLayout {
    
    self.height = 109;
    self.width = (KScreenWidth - 60)/3.0;
    
    {
        _titelLab.size = CGSizeMake(100, 21);
        _titelLab.mj_x = _titelLab.mj_y = 12;
    }
    
    {
        _detailLab.size = CGSizeMake(100, 14);
        _detailLab.mj_x = 12;
        _detailLab.mj_y = _titelLab.bottom + 4;
    }
}

- (UILabel *)titelLab{
    
    if (!_titelLab) {
        _titelLab = [UILabel makeLabelWithText:@"我想聊聊" textColor:UIColorFromRGB(0x333333) font:mMediumFont(15) textAliment:0];
    }
    return _titelLab;
}

- (UILabel *)detailLab{
    
    if (!_detailLab) {
        _detailLab = [UILabel makeLabelWithText:@"分享养猪的秘诀" textColor:UIColorFromRGB(0x999999) font:mFont(10) textAliment:0];
    }
    return _detailLab;
}

@end


@interface DiscoveryHeaderView ()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *tipsLab;
@property (nonatomic, strong) UIView *line1;
@property (nonatomic, strong) UIView *line2;
@property (nonatomic, strong) UILabel *nearbyTitle;

@end


@implementation DiscoveryHeaderView

#pragma mark - init method

- (void)setupUI{
    
    [self addSubview:self.titleLab];
    [self addSubview:self.tipsLab];
    [self addSubview:self.cycleView];
    
    [self addSubview:self.messageView];
    [self addSubview:self.lifeView];
    [self addSubview:self.serviceView];
    
    
    [self addSubview:self.line1];
    [self addSubview:self.nearbyTitle];
    [self addSubview:self.allBtn];
    [self addSubview:self.manBtn];
    [self addSubview:self.womanBtn];
    [self addSubview:self.line2];

}

- (void)setupLayout{
    
    {
        _titleLab.size = CGSizeMake(100, 33);
        _titleLab.mj_x = 15;
        _titleLab.mj_y = 12;
    }
    
    {
        _cycleView.frame = CGRectMake(15, _titleLab.bottom + 15, KScreenWidth -30, 128);
    }
    
    {
        _tipsLab.size = CGSizeMake(200, 22);
        _tipsLab.mj_x = 15;
        _tipsLab.mj_y = _cycleView.bottom + 15;
    }
    
    {
        _messageView.mj_y = _lifeView.mj_y = _serviceView.mj_y = _tipsLab.bottom + 15;
        _messageView.mj_x = 15;
        _lifeView.mj_x = _messageView.right + 10;
        _serviceView.mj_x = _lifeView.right + 10;
    }
    
    {
        _line1.frame = CGRectMake(0, _messageView.bottom + 15, KScreenWidth, 10);
    }
    
    {
        _nearbyTitle.frame = CGRectMake(15, _line1.bottom +15, 200, 22);
    }
    
    {
        _allBtn.size = _womanBtn.size = _manBtn.size = CGSizeMake(60, 24);
        _allBtn.mj_y = _womanBtn.mj_y = _manBtn.mj_y = _nearbyTitle.bottom + 15;
        _allBtn.mj_x = 15;
        _manBtn.mj_x = _allBtn.right + 34;
        _womanBtn.mj_x = _manBtn.right + 34;

    }
    
    {
        _line2.frame = CGRectMake(0, _allBtn.bottom + 15, KScreenWidth, 1);
    }

}

#pragma mark - getter and setter

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = [UIColor colorWithHexString:@"#363636"];
        _titleLab.font = mMediumFont(24);
        _titleLab.text = @"发现";
    }
    return _titleLab;
}

- (UILabel *)tipsLab {
    if (!_tipsLab) {
        _tipsLab = [[UILabel alloc] init];
        _tipsLab.textColor = UIColorFromRGB(0x333333);
        _tipsLab.font = mMediumFont(16);
        _tipsLab.text = @"待标题名称";
    }
    return _tipsLab;
}


- (SDCycleScrollView *)cycleView {
    if (!_cycleView) {
        _cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil];
        _cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycleView.currentPageDotColor = [UIColor primaryColor];
        _cycleView.autoScrollTimeInterval = 2.0;
        _cycleView.backgroundColor = KClearColor;
        _cycleView.pageDotImage = [UIImage imageNamed:@"scrollview_white"];
        _cycleView.currentPageDotImage = [UIImage imageNamed:@"scrollview_green"];
        _cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    }
    return _cycleView;
}


- (DiscoveryView *)messageView{
    if (!_messageView) {
        _messageView = [[DiscoveryView alloc] init];
        _messageView.image = [UIImage imageNamed:@"found_message_bg"];
        _messageView.titelLab.text = @"我想聊聊";
        _messageView.detailLab.text = @"分享养猪的秘诀";
        
        @weakify(self);
        _messageView.tapBlock = ^{
            @strongify(self);
            if (self.dealMessageBlock) {
                self.dealMessageBlock();
            }
        };
    }
    return _messageView;
}

- (DiscoveryView *)lifeView{
    if (!_lifeView) {
        _lifeView = [[DiscoveryView alloc] init];
        _lifeView.image = [UIImage imageNamed:@"found_life_bg"];
        _lifeView.titelLab.text = @"清饲生活";
        _lifeView.detailLab.text = @"分享养猪的秘诀";
        
        @weakify(self);
        _lifeView.tapBlock = ^{
            @strongify(self);
            if (self.dealLifeBlock) {
                self.dealLifeBlock();
            }
        };
    }
    return _lifeView;
}

- (DiscoveryView *)serviceView{
    if (!_serviceView) {
        _serviceView = [[DiscoveryView alloc] init];
        _serviceView.image = [UIImage imageNamed:@"found_service_bg"];
        _serviceView.titelLab.text = @"服务地图";
        _serviceView.detailLab.text = @"分享养猪的秘诀";
        
        @weakify(self);
        _serviceView.tapBlock = ^{
            @strongify(self);
            if (self.dealServiceBlock) {
                self.dealServiceBlock();
            }
        };
    }
    return _serviceView;
}



- (UIView *)line1 {
    if (!_line1) {
        _line1 = [[UIView alloc] init];
        _line1.backgroundColor = [UIColor globalBackgroundColor];
    }
    return _line1;
}
- (UILabel *)nearbyTitle {
    if (!_nearbyTitle) {
        _nearbyTitle = [[UILabel alloc] init];
        _nearbyTitle.textColor = [UIColor colorWithHexString:@"#333333"];
        _nearbyTitle.font = [UIFont boldSystemFontOfSize:16];
        _nearbyTitle.text = @"附近的豚友";
    }
    return _nearbyTitle;
}
- (UIButton *)allBtn {
    if (!_allBtn) {
        _allBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _allBtn.backgroundColor = [UIColor globalBackgroundColor];
        _allBtn.selected = YES;
        _allBtn.layer.cornerRadius = 12;
        _allBtn.layer.masksToBounds = YES;
        [_allBtn setTitle:@"全部" forState:UIControlStateNormal];
        [_allBtn setTitleColor:[UIColor colorWithHexString:@"#A3A3A3"] forState:UIControlStateNormal];
        [_allBtn setTitleColor:[UIColor primaryColor] forState:UIControlStateSelected];
        _allBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _allBtn;
}


- (UIButton *)manBtn{
    if (!_manBtn) {
        _manBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _manBtn.backgroundColor = [UIColor globalBackgroundColor];
        _manBtn.layer.cornerRadius = 12;
        _manBtn.layer.masksToBounds = YES;
        [_manBtn setTitle:@"男" forState:UIControlStateNormal];
        [_manBtn setTitleColor:[UIColor colorWithHexString:@"#A3A3A3"] forState:UIControlStateNormal];
        [_manBtn setTitleColor:[UIColor primaryColor] forState:UIControlStateSelected];
        _manBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _manBtn;
}


- (UIButton *)womanBtn {
    if (!_womanBtn) {
        _womanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _womanBtn.backgroundColor = [UIColor globalBackgroundColor];
        _womanBtn.layer.cornerRadius = 12;
        _womanBtn.layer.masksToBounds = YES;
        [_womanBtn setTitle:@"女" forState:UIControlStateNormal];
        [_womanBtn setTitleColor:[UIColor colorWithHexString:@"#A3A3A3"] forState:UIControlStateNormal];
        [_womanBtn setTitleColor:[UIColor primaryColor] forState:UIControlStateSelected];
        _womanBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _womanBtn;
}


- (UIView *)line2 {
    if (!_line2) {
        _line2 = [[UIView alloc] init];
        _line2.backgroundColor = [UIColor globalBackgroundColor];
    }
    return _line2;
}

@end
